<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
    //从数组中过滤 filter
    var arr = [2,43,54,5,64,656,565]
    // var res = arr.filter(function(item) {
    //   return item < 10;
    // })
    // console.log(res)
    
    //自己定义一个原生的js中的filter方法
    Array.prototype.newFilter = function(callback) {
     var res = [];
     for(var i = 0;i < arr.length;i++) {
         var num = arr[i];
         var flag = callback(num);
         if(flag) {
             res.push(num);
         }
     }
     return res;
    }
    var res = arr.filter(function(item) {
         return item > 10;
    })
    console.log(res)
    
    </script>
</body>
</html>